﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Threading;
using System.Data;
using System.Text;
using System.Xml;
using Gift.WebApp;
using Gift.DAL;
using Gift.Model;

namespace WebApp.admin.basic
{
    public partial class advertisingSet : BaseAdmin
    {

        protected string customXmlPath = "/cn/xml/custom_advertising.xml";
        protected string goodsListXmlPath = "/cn/xml/goods_list.xml";
        protected string homeXmlPath = "/cn/xml/home.xml";
       
        protected string pageXmlPath = "/cn/xml/page.xml";
        protected string promotionGoodsListXmlPath = "/cn/xml/promotion_goods_list.xml";


        // Methods
        private void AdvertisingBind()
        {
            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(base.Server.MapPath(this.homeXmlPath));
                XmlNodeList childNodes = document.SelectSingleNode("home_ad/slides").ChildNodes;
                XmlElement element = (XmlElement)childNodes[0];
                this.imgHomeSlides1.Src = element.GetAttribute("src");
                this.imgHomeSlides1.Alt = element.GetAttribute("alt");
                this.txtHomeSlidesAlt1.Value = element.GetAttribute("alt");
                this.txtHomeSlidesLink1.Value = element.GetAttribute("url");
                XmlElement element2 = (XmlElement)childNodes[1];
                this.imgHomeSlides2.Src = element2.GetAttribute("src");
                this.imgHomeSlides2.Alt = element2.GetAttribute("alt");
                this.txtHomeSlidesAlt2.Value = element2.GetAttribute("alt");
                this.txtHomeSlidesLink2.Value = element2.GetAttribute("url");
                XmlElement element3 = (XmlElement)childNodes[2];
                this.imgHomeSlides3.Src = element3.GetAttribute("src");
                this.imgHomeSlides3.Alt = element3.GetAttribute("alt");
                this.txtHomeSlidesAlt3.Value = element3.GetAttribute("alt");
                this.txtHomeSlidesLink3.Value = element3.GetAttribute("url");
                XmlElement element4 = (XmlElement)childNodes[3];
                this.imgHomeSlides4.Src = element4.GetAttribute("src");
                this.imgHomeSlides4.Alt = element4.GetAttribute("alt");
                this.txtHomeSlidesAlt4.Value = element4.GetAttribute("alt");
                this.txtHomeSlidesLink4.Value = element4.GetAttribute("url");
                XmlElement element5 = (XmlElement)childNodes[4];
                this.imgHomeSlides5.Src = element5.GetAttribute("src");
                this.imgHomeSlides5.Alt = element5.GetAttribute("alt");
                this.txtHomeSlidesAlt5.Value = element5.GetAttribute("alt");
                this.txtHomeSlidesLink5.Value = element5.GetAttribute("url");
        
                XmlNodeList list2 = document.SelectSingleNode("home_ad/slides_right").ChildNodes;
                XmlElement element7 = (XmlElement)list2[0];
                this.imgHomeSlidesRight1.Src = element7.GetAttribute("src");
                this.imgHomeSlidesRight1.Alt = element7.GetAttribute("alt");
                this.txtHomeSlidesRightAlt1.Value = element7.GetAttribute("alt");
                this.txtHomeSlidesRightLink1.Value = element7.GetAttribute("url");
           
    
                XmlNodeList list4 = document.SelectSingleNode("home_ad/new/left").ChildNodes;
                XmlElement element11 = (XmlElement)list4[0];
                this.imgHomeNewLeft1.Src = element11.GetAttribute("src");
                this.imgHomeNewLeft1.Alt = element11.GetAttribute("alt");
                this.txtHomeNewLeftAlt1.Value = element11.GetAttribute("alt");
                this.txtHomeNewLeftLink1.Value = element11.GetAttribute("url");
                XmlElement element12 = (XmlElement)list4[1];
                this.imgHomeNewLeft2.Src = element12.GetAttribute("src");
                this.imgHomeNewLeft2.Alt = element12.GetAttribute("alt");
                this.txtHomeNewLeftAlt2.Value = element12.GetAttribute("alt");
                this.txtHomeNewLeftLink2.Value = element12.GetAttribute("url");
                XmlNodeList list5 = document.SelectSingleNode("home_ad/new/right").ChildNodes;
                XmlElement element13 = (XmlElement)list5[0];
                this.imgHomeNewRight1.Src = element13.GetAttribute("src");
                this.imgHomeNewRight1.Alt = element13.GetAttribute("alt");
                this.txtHomeNewRightAlt1.Value = element13.GetAttribute("alt");
                this.txtHomeNewRightLink1.Value = element13.GetAttribute("url");
                XmlElement element14 = (XmlElement)list5[1];
                this.imgHomeNewRight2.Src = element14.GetAttribute("src");
                this.imgHomeNewRight2.Alt = element14.GetAttribute("alt");
                this.txtHomeNewRightAlt2.Value = element14.GetAttribute("alt");
                this.txtHomeNewRightLink2.Value = element14.GetAttribute("url");
                XmlNodeList list6 = document.SelectSingleNode("home_ad/category_ad").ChildNodes;
                XmlElement element15 = (XmlElement)list6[0];
                this.imgHomeCategory1.Src = element15.GetAttribute("src");
                this.imgHomeCategory1.Alt = element15.GetAttribute("alt");
                this.txtHomeCategoryAlt1.Value = element15.GetAttribute("alt");
                this.txtHomeCategoryLink1.Value = element15.GetAttribute("url");
                XmlElement element16 = (XmlElement)list6[1];
                this.imgHomeCategory2.Src = element16.GetAttribute("src");
                this.imgHomeCategory2.Alt = element16.GetAttribute("alt");
                this.txtHomeCategoryAlt2.Value = element16.GetAttribute("alt");
                this.txtHomeCategoryLink2.Value = element16.GetAttribute("url");
                XmlElement element17 = (XmlElement)list6[2];
                this.imgHomeCategory3.Src = element17.GetAttribute("src");
                this.imgHomeCategory3.Alt = element17.GetAttribute("alt");
                this.txtHomeCategoryAlt3.Value = element17.GetAttribute("alt");
                this.txtHomeCategoryLink3.Value = element17.GetAttribute("url");
                XmlElement element18 = (XmlElement)list6[3];
                this.imgHomeCategory4.Src = element18.GetAttribute("src");
                this.imgHomeCategory4.Alt = element18.GetAttribute("alt");
                this.txtHomeCategoryAlt4.Value = element18.GetAttribute("alt");
                this.txtHomeCategoryLink4.Value = element18.GetAttribute("url");
                XmlElement element19 = (XmlElement)document.SelectSingleNode("home_ad/middle");
                this.imgHomeCategoryMiddle.Src = element19.GetAttribute("src");
                this.imgHomeCategoryMiddle.Alt = element19.GetAttribute("alt");
                this.txtHomeCategoryMiddleAlt.Value = element19.GetAttribute("alt");
                this.txtHomeCategoryMiddleLink.Value = element19.GetAttribute("url");
            
                document.Load(base.Server.MapPath(this.goodsListXmlPath));
                XmlNodeList list8 = document.SelectSingleNode("goods_list_ad/right").ChildNodes;
                XmlElement element25 = (XmlElement)list8[0];
                this.imgGoodsListRight1.Src = element25.GetAttribute("src");
                this.imgGoodsListRight1.Alt = element25.GetAttribute("alt");
                this.txtGoodsListRightAlt1.Value = element25.GetAttribute("alt");
                this.txtGoodsListRightLink1.Value = element25.GetAttribute("url");
                XmlElement element26 = (XmlElement)list8[1];
                this.imgGoodsListRight2.Src = element26.GetAttribute("src");
                this.imgGoodsListRight2.Alt = element26.GetAttribute("alt");
                this.txtGoodsListRightAlt2.Value = element26.GetAttribute("alt");
                this.txtGoodsListRightLink2.Value = element26.GetAttribute("url");
                XmlElement element27 = (XmlElement)list8[2];
                this.imgGoodsListRight3.Src = element27.GetAttribute("src");
                this.imgGoodsListRight3.Alt = element27.GetAttribute("alt");
                this.txtGoodsListRightAlt3.Value = element27.GetAttribute("alt");
                this.txtGoodsListRightLink3.Value = element27.GetAttribute("url");
                XmlElement element28 = (XmlElement)list8[3];
                this.imgGoodsListRight4.Src = element28.GetAttribute("src");
                this.imgGoodsListRight4.Alt = element28.GetAttribute("alt");
                this.txtGoodsListRightAlt4.Value = element28.GetAttribute("alt");
                this.txtGoodsListRightLink4.Value = element28.GetAttribute("url");
                document.Load(base.Server.MapPath(this.promotionGoodsListXmlPath));
                XmlNodeList list9 = document.SelectSingleNode("promotion_goods_list_ad/right").ChildNodes;
                XmlElement element29 = (XmlElement)list9[0];
                this.imgPromotionRight1.Src = element29.GetAttribute("src");
                this.imgPromotionRight1.Alt = element29.GetAttribute("alt");
                this.txtPromotionRightAlt1.Value = element29.GetAttribute("alt");
                this.txtPromotionRightLink1.Value = element29.GetAttribute("url");
                XmlElement element30 = (XmlElement)list9[1];
                this.imgPromotionRight2.Src = element30.GetAttribute("src");
                this.imgPromotionRight2.Alt = element30.GetAttribute("alt");
                this.txtPromotionRightAlt2.Value = element30.GetAttribute("alt");
                this.txtPromotionRightLink2.Value = element30.GetAttribute("url");
                XmlElement element31 = (XmlElement)list9[2];
                this.imgPromotionRight3.Src = element31.GetAttribute("src");
                this.imgPromotionRight3.Alt = element31.GetAttribute("alt");
                this.txtPromotionRightAlt3.Value = element31.GetAttribute("alt");
                this.txtPromotionRightLink3.Value = element31.GetAttribute("url");
                document.Load(base.Server.MapPath(this.pageXmlPath));
                XmlElement element32 = (XmlElement)document.SelectSingleNode("page_ad/top");
                this.imgPageTop.Src = element32.GetAttribute("src");
                this.imgPageTop.Alt = element32.GetAttribute("alt");
                this.txtPageTopAlt.Value = element32.GetAttribute("alt");
                this.txtPageTopLink.Value = element32.GetAttribute("url");
                XmlElement element33 = (XmlElement)document.SelectSingleNode("page_ad/bottom");
                this.imgPageBottom.Src = element33.GetAttribute("src");
                this.imgPageBottom.Alt = element33.GetAttribute("alt");
                this.txtPageBottomAlt.Value = element33.GetAttribute("alt");
                this.txtPageBottomLink.Value = element33.GetAttribute("url");
                XmlElement element34 = (XmlElement)document.SelectSingleNode("page_ad/bottom_freight");
                this.imgPageBottomFreight.Src = element34.GetAttribute("src");
                this.imgPageBottomFreight.Alt = element34.GetAttribute("alt");
                this.txtPageBottomFreightAlt.Value = element34.GetAttribute("alt");
                this.txtPageBottomFreightLink.Value = element34.GetAttribute("url");
            }
            catch
            {
            }
        }

        protected void btnAdvertisingSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                HttpFileCollection files = HttpContext.Current.Request.Files;
                XmlDocument document = new XmlDocument();
                document.Load(base.Server.MapPath(this.homeXmlPath));
                XmlNodeList childNodes = document.SelectSingleNode("home_ad/slides").ChildNodes;
                if (files[0].FileName != "")
                {
                    files[0].SaveAs(base.Server.MapPath("/cn/advertising/HomeSlides1.jpg"));
                }
                XmlElement element = (XmlElement)childNodes[0];
                element.SetAttribute("src", "/cn/advertising/HomeSlides1.jpg");
                element.SetAttribute("alt", this.txtHomeSlidesAlt1.Value);
                element.SetAttribute("url", this.txtHomeSlidesLink1.Value);
                if (files[1].FileName != "")
                {
                    files[1].SaveAs(base.Server.MapPath("/cn/advertising/HomeSlides2.jpg"));
                }
                XmlElement element2 = (XmlElement)childNodes[1];
                element2.SetAttribute("src", "/cn/advertising/HomeSlides2.jpg");
                element2.SetAttribute("alt", this.txtHomeSlidesAlt2.Value);
                element2.SetAttribute("url", this.txtHomeSlidesLink2.Value);
                if (files[2].FileName != "")
                {
                    files[2].SaveAs(base.Server.MapPath("/cn/advertising/HomeSlides3.jpg"));
                }
                XmlElement element3 = (XmlElement)childNodes[2];
                element3.SetAttribute("src", "/cn/advertising/HomeSlides3.jpg");
                element3.SetAttribute("alt", this.txtHomeSlidesAlt3.Value);
                element3.SetAttribute("url", this.txtHomeSlidesLink3.Value);
                if (files[3].FileName != "")
                {
                    files[3].SaveAs(base.Server.MapPath("/cn/advertising/HomeSlides4.jpg"));
                }
                XmlElement element4 = (XmlElement)childNodes[3];
                element4.SetAttribute("src", "/cn/advertising/HomeSlides4.jpg");
                element4.SetAttribute("alt", this.txtHomeSlidesAlt4.Value);
                element4.SetAttribute("url", this.txtHomeSlidesLink4.Value);
                if (files[4].FileName != "")
                {
                    files[4].SaveAs(base.Server.MapPath("/cn/advertising/HomeSlides5.jpg"));
                }
                XmlElement element5 = (XmlElement)childNodes[4];
                element5.SetAttribute("src", "/cn/advertising/HomeSlides5.jpg");
                element5.SetAttribute("alt", this.txtHomeSlidesAlt5.Value);
                element5.SetAttribute("url", this.txtHomeSlidesLink5.Value);
               
                XmlNodeList list2 = document.SelectSingleNode("home_ad/slides_right").ChildNodes;
                if (files[5].FileName != "")
                {
                    files[5].SaveAs(base.Server.MapPath("/cn/advertising/HomeSlidesRight1.jpg"));
                }
                
                XmlNodeList list4 = document.SelectSingleNode("home_ad/new/left").ChildNodes;
                if (files[6].FileName != "")
                {
                    files[6].SaveAs(base.Server.MapPath("/cn/advertising/HomeNewLeft1.jpg"));
                }
                XmlElement element11 = (XmlElement)list4[0];
                element11.SetAttribute("src", "/cn/advertising/HomeNewLeft1.jpg");
                element11.SetAttribute("alt", this.txtHomeNewLeftAlt1.Value);
                element11.SetAttribute("url", this.txtHomeNewLeftLink1.Value);
                if (files[7].FileName != "")
                {
                    files[7].SaveAs(base.Server.MapPath("/cn/advertising/HomeNewLeft2.jpg"));
                }
                XmlElement element12 = (XmlElement)list4[1];
                element12.SetAttribute("src", "/cn/advertising/HomeNewLeft2.jpg");
                element12.SetAttribute("alt", this.txtHomeNewLeftAlt2.Value);
                element12.SetAttribute("url", this.txtHomeNewLeftLink2.Value);
                XmlNodeList list5 = document.SelectSingleNode("home_ad/new/right").ChildNodes;
                if (files[8].FileName != "")
                {
                    files[8].SaveAs(base.Server.MapPath("/cn/advertising/HomeNewRight1.jpg"));
                }
                XmlElement element13 = (XmlElement)list5[0];
                element13.SetAttribute("src", "/cn/advertising/HomeNewRight1.jpg");
                element13.SetAttribute("alt", this.txtHomeNewRightAlt1.Value);
                element13.SetAttribute("url", this.txtHomeNewRightLink1.Value);
                if (files[9].FileName != "")
                {
                    files[9].SaveAs(base.Server.MapPath("/cn/advertising/HomeNewRight2.jpg"));
                }
                XmlElement element14 = (XmlElement)list5[1];
                element14.SetAttribute("src", "/cn/advertising/HomeNewRight2.jpg");
                element14.SetAttribute("alt", this.txtHomeNewRightAlt2.Value);
                element14.SetAttribute("url", this.txtHomeNewRightLink2.Value);
                XmlNodeList list6 = document.SelectSingleNode("home_ad/category_ad").ChildNodes;
                if (files[10].FileName != "")
                {
                    files[10].SaveAs(base.Server.MapPath("/cn/advertising/HomeCategory1.jpg"));
                }
                XmlElement element15 = (XmlElement)list6[0];
                element15.SetAttribute("src", "/cn/advertising/HomeCategory1.jpg");
                element15.SetAttribute("alt", this.txtHomeCategoryAlt1.Value);
                element15.SetAttribute("url", this.txtHomeCategoryLink1.Value);
                if (files[11].FileName != "")
                {
                    files[11].SaveAs(base.Server.MapPath("/cn/advertising/HomeCategory2.jpg"));
                }
                XmlElement element16 = (XmlElement)list6[1];
                element16.SetAttribute("src", "/cn/advertising/HomeCategory2.jpg");
                element16.SetAttribute("alt", this.txtHomeCategoryAlt2.Value);
                element16.SetAttribute("url", this.txtHomeCategoryLink2.Value);
                if (files[12].FileName != "")
                {
                    files[12].SaveAs(base.Server.MapPath("/cn/advertising/HomeCategory3.jpg"));
                }
                XmlElement element17 = (XmlElement)list6[2];
                element17.SetAttribute("src", "/cn/advertising/HomeCategory3.jpg");
                element17.SetAttribute("alt", this.txtHomeCategoryAlt3.Value);
                element17.SetAttribute("url", this.txtHomeCategoryLink3.Value);
                if (files[13].FileName != "")
                {
                    files[13].SaveAs(base.Server.MapPath("/cn/advertising/HomeCategory4.jpg"));
                }
                XmlElement element18 = (XmlElement)list6[3];
                element18.SetAttribute("src", "/cn/advertising/HomeCategory4.jpg");
                element18.SetAttribute("alt", this.txtHomeCategoryAlt4.Value);
                element18.SetAttribute("url", this.txtHomeCategoryLink4.Value);
                XmlElement element19 = (XmlElement)document.SelectSingleNode("home_ad/middle");
                if (files[14].FileName != "")
                {
                    files[14].SaveAs(base.Server.MapPath("/cn/advertising/HomeCategoryMiddle.jpg"));
                }
                element19.SetAttribute("src", "/cn/advertising/HomeCategoryMiddle.jpg");
                element19.SetAttribute("alt", this.txtHomeCategoryMiddleAlt.Value);
                element19.SetAttribute("url", this.txtHomeCategoryMiddleLink.Value);
        
                document.Save(base.Server.MapPath(this.homeXmlPath));

                document.Load(base.Server.MapPath(this.goodsListXmlPath));
              
                XmlNodeList list11 = document.SelectSingleNode("goods_list_ad/right").ChildNodes;
                if (files[15].FileName != "")
                {
                    files[15].SaveAs(base.Server.MapPath("/cn/advertising/GoodsListRight1.jpg"));
                }
                XmlElement element26 = (XmlElement)list11[0];
                element26.SetAttribute("src", "/cn/advertising/GoodsListRight1.jpg");
                element26.SetAttribute("alt", this.txtGoodsListRightAlt1.Value);
                element26.SetAttribute("url", this.txtGoodsListRightLink1.Value);
                if (files[16].FileName != "")
                {
                    files[16].SaveAs(base.Server.MapPath("/cn/advertising/GoodsListRight2.jpg"));
                }
                XmlElement element27 = (XmlElement)list11[1];
                element27.SetAttribute("src", "/cn/advertising/GoodsListRight2.jpg");
                element27.SetAttribute("alt", this.txtGoodsListRightAlt2.Value);
                element27.SetAttribute("url", this.txtGoodsListRightLink2.Value);
                if (files[17].FileName != "")
                {
                    files[17].SaveAs(base.Server.MapPath("/cn/advertising/GoodsListRight3.jpg"));
                }
                XmlElement element28 = (XmlElement)list11[2];
                element28.SetAttribute("src", "/cn/advertising/GoodsListRight3.jpg");
                element28.SetAttribute("alt", this.txtGoodsListRightAlt3.Value);
                element28.SetAttribute("url", this.txtGoodsListRightLink3.Value);
                if (files[18].FileName != "")
                {
                    files[18].SaveAs(base.Server.MapPath("/cn/advertising/GoodsListRight4.jpg"));
                }
                XmlElement element29 = (XmlElement)list11[3];
                element29.SetAttribute("src", "/cn/advertising/GoodsListRight4.jpg");
                element29.SetAttribute("alt", this.txtGoodsListRightAlt4.Value);
                element29.SetAttribute("url", this.txtGoodsListRightLink4.Value);
                document.Save(base.Server.MapPath(this.goodsListXmlPath));
                document.Load(base.Server.MapPath(this.promotionGoodsListXmlPath));
                XmlNodeList list12 = document.SelectSingleNode("promotion_goods_list_ad/right").ChildNodes;
                XmlElement element30 = (XmlElement)list12[0];
                if (files[19].FileName != "")
                {
                    files[19].SaveAs(base.Server.MapPath("/cn/advertising/PromotionGoodsListRight1.jpg"));
                }
                element30.SetAttribute("src", "/cn/advertising/PromotionGoodsListRight1.jpg");
                element30.SetAttribute("alt", this.txtPromotionRightAlt1.Value);
                element30.SetAttribute("url", this.txtPromotionRightLink1.Value);
                XmlElement element31 = (XmlElement)list12[1];
                if (files[20].FileName != "")
                {
                    files[20].SaveAs(base.Server.MapPath("/cn/advertising/PromotionGoodsListRight2.jpg"));
                }
                element31.SetAttribute("src", "/cn/advertising/PromotionGoodsListRight2.jpg");
                element31.SetAttribute("alt", this.txtPromotionRightAlt2.Value);
                element31.SetAttribute("url", this.txtPromotionRightLink2.Value);
                XmlElement element32 = (XmlElement)list12[2];
                if (files[21].FileName != "")
                {
                    files[21].SaveAs(base.Server.MapPath("/cn/advertising/PromotionGoodsListRight3.jpg"));
                }
                element32.SetAttribute("src", "/cn/advertising/PromotionGoodsListRight3.jpg");
                element32.SetAttribute("alt", this.txtPromotionRightAlt3.Value);
                element32.SetAttribute("url", this.txtPromotionRightLink3.Value);
                document.Save(base.Server.MapPath(this.promotionGoodsListXmlPath));
                document.Load(base.Server.MapPath(this.pageXmlPath));
                XmlElement element33 = (XmlElement)document.SelectSingleNode("page_ad/top");
                if (files[22].FileName != "")
                {
                    files[22].SaveAs(base.Server.MapPath("/cn/advertising/PageTop.jpg"));
                }
                element33.SetAttribute("src", "/cn/advertising/PageTop.jpg");
                element33.SetAttribute("alt", this.txtPageTopAlt.Value);
                element33.SetAttribute("url", this.txtPageTopLink.Value);
                XmlElement element34 = (XmlElement)document.SelectSingleNode("page_ad/bottom");
                if (files[23].FileName != "")
                {
                    files[23].SaveAs(base.Server.MapPath("/cn/advertising/PageBottom.jpg"));
                }
                element34.SetAttribute("src", "/cn/advertising/PageBottom.jpg");
                element34.SetAttribute("alt", this.txtPageBottomAlt.Value);
                element34.SetAttribute("url", this.txtPageBottomLink.Value);
                XmlElement element35 = (XmlElement)document.SelectSingleNode("page_ad/bottom_freight");
                if (files[24].FileName != "")
                {
                    files[24].SaveAs(base.Server.MapPath("/cn/advertising/PageBottomFreight.jpg"));
                }
                element35.SetAttribute("src", "/cn/advertising/PageBottomFreight.jpg");
                element35.SetAttribute("alt", this.txtPageBottomFreightAlt.Value);
                element35.SetAttribute("url", this.txtPageBottomFreightLink.Value);
                document.Save(base.Server.MapPath(this.pageXmlPath));
                document.Load(base.Server.MapPath(this.customXmlPath));
                XmlElement element36 = (XmlElement)document.SelectSingleNode("custom_ad");
                if (files.Count > 25)
                {
                    Array array = base.Request.Form["hdCustomAd"].Split(new char[] { ',' });
                    Array array2 = base.Request.Form["customAdAlt"].Split(new char[] { ',' });
                    Array array3 = base.Request.Form["customAdUrl"].Split(new char[] { ',' });
                    element36.RemoveAll();
                    for (int j = 25; j < files.Count; j++)
                    {
                        int index = j - 25;
                        string path = "";
                        if (files[j].FileName != "")
                        {
                            path = "/cn/advertising/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                            files[j].SaveAs(base.Server.MapPath(path));
                            if (array.GetValue(index).ToString() != "0")
                            {
                                File.Delete(base.Server.MapPath(array.GetValue(index).ToString()));
                            }
                        }
                        else
                        {
                            path = array.GetValue(index).ToString();
                        }
                        XmlElement newChild = document.CreateElement("ad");
                        newChild.SetAttribute("src", path);
                        newChild.SetAttribute("alt", array2.GetValue(index).ToString());
                        newChild.SetAttribute("url", array3.GetValue(index).ToString());
                        element36.AppendChild(newChild);
                        Thread.Sleep(100);
                    }
                }
                else
                {
                    element36.RemoveAll();
                }
                document.Save(base.Server.MapPath(this.customXmlPath));
                base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");location.href=\"advertisingSet.aspx\";</script>");
            }
            catch
            {
            }
        }

        protected StringBuilder CustomAdBind()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(base.Server.MapPath(this.customXmlPath));
                XmlNodeList childNodes = document.SelectSingleNode("custom_ad").ChildNodes;
                for (int i = 0; i < childNodes.Count; i++)
                {
                    XmlElement element = (XmlElement)childNodes[i];
                    builder.AppendLine("<tr>");
                    builder.AppendLine("<td>自定义广告</td>");
                    builder.AppendLine("<td><img id=\"img1\" src=\"" + element.GetAttribute("src") + "\" style=\"width: 380px;\" alt=\"" + element.GetAttribute("alt") + "\" /></td>");
                    builder.AppendLine("<td>");
                    builder.AppendLine("图片地址：" + element.GetAttribute("src") + "<br /><br />");
                    builder.AppendLine("图片路径：<input name=\"fileCustomAd\" type=\"file\" class=\"file\" /><br /><br />");
                    builder.AppendLine("<span class=\"imgClass\">图片分辨率：72像素 格式：jpg,bmp,gif,png</span><br /><br />");
                    builder.AppendLine("图片描述：<input name=\"customAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + element.GetAttribute("alt") + "\" /><br /><br />");
                    builder.AppendLine("链接地址：<input name=\"customAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + element.GetAttribute("url") + "\" /><input name=\"hdCustomAd\" type=\"hidden\" value=\"" + element.GetAttribute("src") + "\" />");
                    builder.AppendLine("</td>");
                    builder.AppendLine("<td><input id=\"Button1\" type=\"button\" class=\"formButton\" value=\"删除广告\" title=\"删除广告\" onclick=\"DelCustomAd(this.parentNode.parentNode.rowIndex);\" /></td>");
                    builder.AppendLine("</tr>");
                }
            }
            catch
            {
            }
            return builder;
        }

    

        protected override object LoadPageStateFromPersistenceMedium()
        {
            byte[] inArray = ViewStateCompression.DeCompress(Convert.FromBase64String(base.Request.Form.Get("__MSPVSTATE")));
            LosFormatter formatter = new LosFormatter();
            return formatter.Deserialize(Convert.ToBase64String(inArray));
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
            //{
            //    base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
            //}
            if (!base.IsPostBack)
            {
                if (int.Parse(base.Administrator.CompanyId) > 1)
                {
                    Response.Redirect("banner.aspx");
                }
                else
                {
                    this.AdvertisingBind();
                }
            }
        }

        protected override void SavePageStateToPersistenceMedium(object pViewState)
        {
            LosFormatter formatter = new LosFormatter();
            StringWriter output = new StringWriter();
            formatter.Serialize(output, pViewState);
            string hiddenFieldInitialValue = Convert.ToBase64String(ViewStateCompression.Compress(Convert.FromBase64String(output.ToString())));
            base.ClientScript.RegisterHiddenField("__MSPVSTATE", hiddenFieldInitialValue);
        }
    }
}



